package org.apache.flink.runtime.messages.webmonitor;

import static org.apache.flink.util.Preconditions.checkNotNull;

import org.apache.flink.api.common.ResourceStatus;
import org.apache.flink.runtime.rest.messages.ResponseBody;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

/** The status of Resources of a consumer. */
public class ResourceStatusInfo implements ResponseBody, InfoMessage {
    private static final long serialVersionUID = 1L;

    public static final String FIELD_NAME_STATUS = "status";

    @JsonProperty(FIELD_NAME_STATUS)
    private final ResourceStatus resourceStatus;

    @JsonCreator
    public ResourceStatusInfo(@JsonProperty(FIELD_NAME_STATUS) ResourceStatus resourceStatus) {
        this.resourceStatus = checkNotNull(resourceStatus);
    }

    @JsonIgnore
    public ResourceStatus getResourceStatus() {
        return resourceStatus;
    }

    @Override
    public int hashCode() {
        return resourceStatus.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        } else if (obj instanceof ResourceStatusInfo) {
            ResourceStatusInfo that = (ResourceStatusInfo) obj;
            return resourceStatus.equals(that.resourceStatus);
        } else {
            return false;
        }
    }

    @Override
    public String toString() {
        return "ResourceStatusInfo { " + resourceStatus + " }";
    }
}
